﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bitirme.Controllers;
using Bitirme.DAL.Entities;

namespace Bitirme.Views
{
    public partial class ShowAssignment : System.Web.UI.Page
    {
        Project project;
        static List<ScheduleEventItem> events;
        //List<Employee> employeeList;
        //List<WorkPackage> dependencies;

        protected void Page_Load(object sender, EventArgs e)
        {


            //EmployeeHandler emHandler = new EmployeeHandler();
            //employeeList = emHandler.GetAllEmployeesWithSkills();
            

            //List<Assignment> assignments = asHandler.GetAssignmentsByEmployeeID(employeeList[1].ID);

            //Scheduler scheduler = new Scheduler(projectID);
            //List<ScheduledWorkPackages> wps = new List<ScheduledWorkPackages>();
            //List<Assignment> assignedList = scheduler.naber();
           // asHandler.InsertAssignmentsByProjectID(assignedList, projectID);

            /*project = prHandler.GetProjectsWithAllAttributesByID(1);
            allProjects.Add(project);
            project = prHandler.GetProjectsWithAllAttributesByID(2);
            allProjects.Add(project);*/

            string iD = Request.QueryString["id"];
            int projectID = Int32.Parse(iD);
           /* AssignmentHandler asHandler = new AssignmentHandler();

            ProjectHandler prHandler = new ProjectHandler();
            project = prHandler.GetProjectsWithAllAttributesByID(projectID);
            List<Project> allProjects = new List<Project>();

            List<Project> projects = prHandler.GetAllProjects();

            foreach (Project projectItem in projects) {

                project = prHandler.GetProjectsWithAllAttributesByID(projectItem.ID);
                allProjects.Add(project);
            }

            ScheduleInterProjects schedulerAll = new ScheduleInterProjects(allProjects);
            List<Assignment> assignedList = schedulerAll.assignWorkPackages();
            */
            ScheduleEventItem tempEventItem;
            ScheduleEventHandler scheduleEventHandler = new ScheduleEventHandler();
            Project tempProject;

            AssignmentHandler asHandler = new AssignmentHandler();
            List<Assignment> assignedList = asHandler.GetAssignmentsByProjectID(projectID);

            events = new List<ScheduleEventItem>();
            foreach (Assignment assignedItem in assignedList) {

                tempEventItem = new ScheduleEventItem();
                tempProject = asHandler.GetProjectByWorkPackageID(assignedItem.WorkPackage.ID);
                tempEventItem.EmployeeName = assignedItem.Employee.Name;
                tempEventItem.WorkPackageName = assignedItem.WorkPackage.Name;
                tempEventItem.StartDate = assignedItem.StartDate.ToString();
                tempEventItem.EndDate = assignedItem.EndDate.ToString();
                tempEventItem.WorkPackageID = assignedItem.WorkPackage.ID;
                tempEventItem.Title = assignedItem.Employee.Name + " - " + assignedItem.WorkPackage.Name;
                if(tempProject.ID == projectID)
                    events.Add(tempEventItem);
            }
            //asHandler.InsertAssignments(assignedList);
        }

        [System.Web.Services.WebMethod]
        public static List<ScheduleEventItem> GetEvents()
        {
            return events;
        }
    }
}